#include "memory.h"

void* memset(void* ptr, const int c, const size_t size)
{
    uint8_t* b_ptr = (uint8_t*)ptr; 
    size_t i; 

    for (i = 0; i < size; i++) {
        b_ptr[i] = (uint8_t)c; 
    }

    return ptr; 
}

const int memcmp(void* mem1, void* mem2, const size_t size)
{
    char* c1 = mem1;
    char* c2 = mem2; 
    size_t i = size; 

    while (i-- > 0) {
        if (*c1 != *c2) {
            return *c1 < *c2 ? -1 : +1; 
        }

        c1++; 
        c2++; 
    }

    return 0; 
}

void* memcpy(void* dest, void* src, size_t len) 
{
    char* d = (char*)dest;
    char* s = (char*)src;

    while (len--) {
        *d++ = *s++; 
    }

    return dest; 
}